<template>
	<view>
		<view class="uni-mask" v-show="show" :style="{ top: offsetTop + 'px' }" @click="hide" @touchmove.stop.prevent="moveHandle" catchtouchmove="ture"></view>
		<view class="uni-popup" :class="'uni-popup-' + position + ' ' + 'uni-popup-' + mode" v-show="show">
			<image src="../../static/images/popup_03.png" class="popup_img" v-show="show" @click="hide"></image>
			<slot></slot>
			<view v-if="position === 'middle' && mode === 'insert'" class=" uni-icon uni-icon-close" :class="{
					'uni-close-bottom': buttonMode === 'bottom',
					'uni-close-right': buttonMode === 'right'
				}" @click="closeMask"></view>
			<view class="sales_return">
				<view class="sales_return_title">退货原因</view>
				<view>
					<radio-group>
                       <label class="" v-for="(item, index) in items" :key="index">
						  <view class="redioList" @click="radioChange(index)">
							  <view class="radioText">{{ item.content }}</view>
							  <view>
							     <radio :checked="index === current"  color="#e94d6a"/>
							  </view> 
						  </view>
                     </label>
                    </radio-group>
				</view>
				<view class="sales_return_button">
					<button @click="showValue">确定</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'uni-popupCancel',
		props: {
			/**
			 * 页面显示
			 */
			show: {
				type: Boolean,
				default: false
			},
			/**
			 * 对齐方式
			 */
			position: {
				type: String,
				//top - 顶部， middle - 居中, bottom - 底部
				default: 'middle'
			},
			/**
			 * 显示模式
			 */
			mode: {
				type: String,
				default: 'insert'
			},
			/**
			 * 额外信息
			 */
			msg: {
				type: String,
				default: ''
			},
			/**
			 * h5遮罩是否到顶
			 */
			h5Top: {
				type: Boolean,
				default: false
			},
			buttonMode: {
				type: String,
				default: 'bottom'
			},
			returnReason: Array
		},
		data() {
			return {
				offsetTop: 0,
				items: [],
                current: 0
			};
		},
		watch: {
			h5Top(newVal) {
				if (newVal) {
					this.offsetTop = 44;
				} else {
					this.offsetTop = 0;
				}
			},
			returnReason: {
				handler() {
					this.items = JSON.parse(JSON.stringify(this.returnReason));
				},
				deep: true
			}
		},
		created() {
			let offsetTop = 0;
			//#ifdef H5
			if (!this.h5Top) {
				offsetTop = 44;
			} else {
				offsetTop = 0;
			}
			//#endif
			this.offsetTop = offsetTop;
		},
		mounted(){
			this.items = JSON.parse(JSON.stringify(this.returnReason));
		},
		methods: {
			showValue(){
				console.log(this.current);
				this.$emit('returnReason',this.items[this.current].content);
				this.hide();		
			},
			hide() {
				if (this.mode === 'insert' && this.position === 'middle') return;
				this.$emit('hidePopup');
			},
			closeMask() {
				if (this.mode === 'insert') {
					this.$emit('hidePopup');
				}
			},
			radioChange(index) {
				this.current = index;
				console.log(this.current);
            },
			moveHandle() {}
		}
	};
</script>
<style>
	.uni-mask {
		position: fixed;
		z-index: 0;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		background-color: rgba(0, 0, 0, 0.3);
	}
    .popup_img{
    	width:44upx;
    	height:44upx;
    	position: absolute;
    	top:-20upx;
    	right:10upx;
		z-index: 9999999;
    }
	.uni-popup {
		position: fixed;
		z-index: 999;
		background-color: #ffffff;
		border-top-left-radius:25upx;
		border-top-right-radius:25upx;
	}

	.uni-popup-middle {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
	}

	.uni-popup-middle.uni-popup-insert {
		min-width: 380upx;
		min-height: 380upx;
		max-width: 100%;
		max-height: 80%;
		transform: translate(-50%, -65%);
		background: none;
		box-shadow: none;
	}

	.uni-popup-middle.uni-popup-fixed {
		border-radius: 10upx;
		padding: 30upx;
	}

	.uni-close-bottom,
	.uni-close-right {
		position: absolute;
		bottom: -180upx;
		/* text-align: center; */
		border-radius: 50%;
		color: #f5f5f5;
		font-size: 60upx;
		font-weight: bold;
		opacity: 0.8;
		z-index: -1;
	}

	.uni-close-right {
		right: -60upx;
		top: -80upx;
	}

	.uni-close-bottom:after {
		content: '';
		position: absolute;
		width: 0px;
		border: 1px #f5f5f5 solid;
		top: -200upx;
		bottom: 56upx;
		left: 50%;
		transform: translate(-50%, -0%);
		opacity: 0.8;
	}

	.uni-popup-top {
		top: 0;
		left: 0;
		width: 100%;
		height: 100upx;
		line-height: 100upx;
		/* text-align: center; */
	}

	.uni-popup-bottom {
		left: 0;
		bottom: 0;
		width: 100%;
		/* min-height: 100upx;
		line-height: 100upx; */
		/* text-align: center; */
	}
	.cancel_order{
		text-align: center;
		margin-top:50upx;
	}
	.cancel_order_title{
		font-size:36upx;
		color:#333333;
		font-weight: bold;
	}
	.cancel_order_button{
		margin-top: 60upx;
		margin-bottom: 30upx;
	}
	.cancel_order_button button:nth-of-type(1){
		font-size:28upx;
		color: #333333;
		background: #f4a6b4;
		height: auto;
		width:40%;
		display: inline-block;
		margin-right: 30upx;
	}
	.cancel_order_button button:nth-of-type(2){
		font-size:28upx;
		color: #fff;
		background: #e94d6a;
		height: auto;
		width:40%;
		display: inline-block;
	}
	.sales_return{
		
	}
	.sales_return_title{
		font-size: 30upx;
		color: #222222;
		text-align: center;
		margin:30upx 0;
		font-weight: bold;
	}
	.redioList{
		display: flex;
		justify-content: space-between;
		border-bottom: 1upx solid #e0e0e0;
		margin-top:30upx;
		padding:20upx 0;
		margin:0 20upx;
	}
	.radioText{
		width: 650upx;
		font-size: 30upx;
		color: #222222;
		margin-top:10upx 0;
		overflow:hidden;
		text-overflow:ellipsis;
		white-space:nowrap;
	}
	.sales_return_button button{
		width:100%;
		height:auto;
		background: #e94d6a;
		color: #fffefe;
		font-size: 30upx;
		margin-top:100upx;
		border-radius: 0;
	}
</style>